/*
 * © 2010 Autodata Solutions Company. All Rights Reserved
 * This source code is the confidential and proprietary information of Autodata Solutions Company.
 * The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
 * without the prior written consent of Autodata Solutions Company.
 */
Ext.ns('net.autodata.swatch');
(function () {
	
	/**
	 * @class SwatchPanel
	 * @extends Ext.BoxComponent
	 * @namespace net.autodata.swatch
	 */
	var Panel = Ext.extend(Ext.BoxComponent, {
		
		autoEl: {
			tag: 'div',
			cls: 'swatches-panel'
		},
		
		swatches: undefined,
		items: undefined,
		
		getSwatches: function ()
		{
			return this.swatches;
		},
		
		setSwatches: function (swatches)
		{
			this.swatches = swatches;
			this.refresh();
		},
		
		onRender: function ()
		{
			Panel.superclass.onRender.apply(this, arguments);
			this.refresh();
		},
		
		refresh: function ()
		{	
			if (!this.rendered) {
				return;
			}
			
			var WRAPPER = net.autodata.swatch.SwatchWrapper;
			
			var dom = this.el.dom;
			
			this.removeAll();
			
			items = [];
			
			Ext.each(this.swatches, function (swatch) {				
				items.push(new WRAPPER({
					swatch: swatch,
					renderTo: dom
				}));				
			}, this);
			
			this.items = items;
		},
		
		/**
		 * @private
		 */
		removeAll: function ()
		{
			Ext.each(this.items, function (item) {
				item.destroy();
			}, this);
			delete this.items;
		}	
	});
	
	net.autodata.swatch.SwatchesPanel = Panel;
})();